package com.zp.qualitypractice.Mvp;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by izp on 2017/4/14.
 */

public abstract class BaseActivity <T extends MvpBase.BasePresenter> extends  AppCompatActivity implements MvpBase.BaseView {
//    /**
//     * 让后代去实现，不过要看一下bindPresenter调用的生命周期
//     */
//    @Override
//    public void bindPresenter() {
//
//    }
    protected T mPresenter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bindPresenter();
        mPresenter = createPresenter();
        if (null!=mPresenter){
            mPresenter.attachView(this);
        }
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (null!=mPresenter){
            mPresenter.detachView();
        }
    }
    protected abstract T createPresenter();

}
